package com.szrt.javaweb;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.szrt.javaweb.demo.UserEntity;



@Controller
public class ModelAndViewController {
	
	
	/*
	 * http://localhost:8080/mvn-springmvc-01-1609/modelAndViewDemo01
	 */
	@RequestMapping("/modelAndViewDemo01")
	public ModelAndView modelAndViewDemo01(){
		
		ModelAndView modelAndView = new ModelAndView();
		
		//1 往里面放什么数据
		
		//UserEntity user = new UserEntity();
		
		//username
		modelAndView.addObject("username", "Scott");
		
		
		//2跳到什么页面去 /
		modelAndView.setViewName("modelAndView/success");
		
		return modelAndView;
		
	}
	
	/*
	 * http://localhost:8080/mvn-springmvc-01-1609/modelAndViewDemo02
	 */
	@RequestMapping("/modelAndViewDemo02")
	public ModelAndView modelAndViewDemo02(){
		
		ModelAndView modelAndView = new ModelAndView();
		
		//1 往里面放什么数据
		
		UserEntity user = new UserEntity();
		user.setUsername("Scott");
		user.setAge(33);
		
		modelAndView.addObject("user", user);
		
		
		//2跳到什么页面去 /
		modelAndView.setViewName("modelAndView/success");
		
		
		return modelAndView;
		
	}
	
	/*
	 * http://localhost:8080/mvn-springmvc-01-1609/modelAndViewDemo03
	 */
	@RequestMapping("/modelAndViewDemo03")
	public ModelAndView modelAndViewDemo03(){
		
		ModelAndView modelAndView = new ModelAndView();
		
		//1 往里面放什么数据
		
		UserEntity user = new UserEntity();
		user.setUsername("Scott");
		user.setAge(33);
		
		String [] bj1609 = new String[]{"wc","srx","njj"};
		
		//如何把一个数组转化成1个list
		List<String> names =Arrays.asList(bj1609);
		
		modelAndView.addObject("user", user);
		modelAndView.addObject("names", names);
		
		
		//2跳到什么页面去 /
		modelAndView.setViewName("modelAndView/success");
		
		
		return modelAndView;
		
	}

}
